home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Source.bin / DialogBox.java < prev    next >
Text File  |  1998-10-24  |  3KB  |  101 lines

  1. package symantec.itools.awt.util.dialog;
  2.  
  3. import java.awt.Button;
  4. import java.awt.Event;
  5. import java.awt.Frame;
  6. import java.awt.Dialog;
  7. import java.awt.Rectangle;
  8.  
  9. /**
  10.  * This implements a non-resizable dialog box.
  11.  * It has an available button and closes itself as needed.
  12.  */
  13. public class DialogBox extends Dialog {
  14.  
  15.     /**
  16.      * An available button.
  17.      */
  18.     protected Button okButton;
  19.  
  20.     /**
  21.      *
  22.      * Constructs a DialogBox with the given parent.
  23.      * @param f the frame of this dialogÆs parent
  24.      */
  25.     public DialogBox(Frame f) {
  26.         this(f, false);
  27.     }
  28.  
  29.     /**
  30.      * Constructs a DialogBox with the given parent and modality.
  31.      * @param f the frame of this dialogÆs parent
  32.      * @param modal true to construct a modal dialog, false to construct a
  33.      * non-modal dialog
  34.      */
  35.     public DialogBox(Frame f, boolean modal) {
  36.         this(f, "", modal);
  37.     }
  38.  
  39.     /**
  40.      * Constructs a DialogBox with the given parent, title, and modality.
  41.      * @param f the frame of this dialogÆs parent
  42.      * @param s the title for this dialog
  43.      * @param modal true to construct a modal dialog, false to construct a
  44.      * non-modal dialog
  45.      */
  46.     public DialogBox(Frame f, String s, boolean modal) {
  47.         super(f, s, modal);
  48.         if ( modal )
  49.             setResizable(false);
  50.         else
  51.             setResizable(true);
  52.     }
  53.  
  54.     /**
  55.      * Makes this component visible.
  56.      * <p>
  57.      * This is a standard Java AWT method which gets called to show this
  58.      * component. If this component was invisible due to a previous hide()
  59.      * call it makes this component visible again.
  60.      */
  61.     public void show() {
  62.         Rectangle bounds = getParent().bounds();
  63.         Rectangle abounds = bounds();
  64.  
  65.         move(bounds.x + (bounds.width - abounds.width) / 2,
  66.              bounds.y + (bounds.height - abounds.height) /2);
  67.  
  68.         super.show();
  69.     }
  70.  
  71.     /**
  72.      * Hides and disposes of the dialog.
  73.      */
  74.     protected void closeDialog() {
  75.         hide();
  76.         dispose();
  77.     }
  78.  
  79.     /**
  80.      * Processes events for this component.
  81.      * <p>
  82.      * This is a standard Java AWT method which gets called by the AWT to
  83.      * handle this component's events. The default handler for components
  84.      * dispatches to one of the following methods as needed: action(),
  85.      * gotFocus(), lostFocus(), keyDown(), keyUp(), mouseEnter(), mouseExit(),
  86.      * mouseMove(), mouseDrag(), mouseDown(), or mouseUp().
  87.      *
  88.      * @param event the event to handle
  89.      * @return true if the event was handled and no further action is needed,
  90.      * false to pass the event to this component's parent
  91.      */
  92.     public boolean handleEvent(Event event) {
  93.         if ((event.target == okButton && event.id == Event.ACTION_EVENT) ||
  94.             (event.target == this && event.id == Event.WINDOW_DESTROY))
  95.             closeDialog();
  96.  
  97.         return super.handleEvent(event);
  98.     }
  99.  
  100. }
  101.